package com.jp.knowledge.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by jiayen on 16/10/14.
 *
 * sharede帮助工具类
 */

public class SharedUtil {
    public static final String TOKEN = "token";
    public static final String UUID = "uuid";
    public static final String last_refresh_time="last_refresh_time";//最后刷新时间
    public static final String COMM_FONT_SIZE="comm_font_size";//需要修改字体的地方使用
    public static final String COMM_FONT_SIZE_TEXT="comm_font_size_text";//需要修改字体的地方使用
    public static final String  CUR_HEADLINE_TYPE_ID="cur_headline_type_id";
    private SharedPreferences preferences;
    private static SharedUtil instance;
    private Context mContext;
    private SharedUtil(Context context){
        try {
            this.mContext =context;
            preferences =context.getSharedPreferences("jp_date",Context.MODE_PRIVATE);
        }catch (Exception e){

        }

    }

    public static SharedUtil getInstance(Context context){
        if(instance==null)instance=new SharedUtil(context);
        return instance;
    }

    /**
     * 临时保存token与uuid
     * @param token
     * @param uuid
     */
    public void saveTokenAndUUId(String token,String uuid){
       SharedPreferences.Editor editor =  preferences.edit();
        editor.putString(TOKEN,token);
        editor.putString(UUID,uuid);
        editor.commit();
    }


    /**
     * 保存修改的字体大小值 单位sp
     */
    public void saveCommFontSize(int size){
        SharedPreferences.Editor editor =  preferences.edit();
        editor.putInt(COMM_FONT_SIZE,size);
        editor.commit();
    }


    /**
     * 保存修改的字体大小值 单位sp
     */
    public void saveCommFontSize(String  str){
        SharedPreferences.Editor editor =  preferences.edit();
        editor.putString(COMM_FONT_SIZE_TEXT,str);
        editor.commit();
    }


    /**
     * 获取字体大小
     */
    public String getCommFontSizeText(){

        return  preferences.getString(COMM_FONT_SIZE_TEXT,null);
    }

    /**
     * 获取字体大小
     */
    public int getCommFontSize(){
        return  preferences.getInt(COMM_FONT_SIZE,0);
    }
    /**
     * 清楚登录信息
     */
    public void cleanLoginInfo(){
        SharedPreferences.Editor editor =  preferences.edit();
        editor.putString(TOKEN,"");
        editor.putString(UUID,"");
        editor.commit();
    }

    /**
     * 保存最后刷新时间
     */
    public void saveLastRefreshTime(){

    }

    public String getToken(){
        if(preferences==null)return  null;
        return preferences.getString(TOKEN,null);
    }
    public String getUuid(){
        if(preferences==null)return  null;
        return preferences.getString(UUID,null);
    }

    /***
     * 保存当前的headlineid
     * @param curTypeId
     */
    public void saveCurHeadLineTypeId(String curTypeId){
        SharedPreferences.Editor editor =  preferences.edit();
        editor.putString(CUR_HEADLINE_TYPE_ID,curTypeId);
        editor.commit();
    }

    public String getCurHeadlineTypeId(){
        return preferences.getString(CUR_HEADLINE_TYPE_ID,null);
    }

}
